package com.lyshop.jinding.view;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.lyshop.jinding.R;
import com.lyshop.jinding.utils.DataUtils;
import com.lyshop.jinding.utils.TimeCount;

public class TakeMoneyRuleDialog extends MyDialog implements View.OnClickListener {

    private View rootView;
    private TextView tv_content;
    private TextView tv_link;


    public TakeMoneyRuleDialog(Context context, String rule) {
        this(context, false, Gravity.CENTER, rule);
    }

    public TakeMoneyRuleDialog(Context context, boolean isCancelAble, int gravity, String rule) {
        super(context, isCancelAble, gravity);
        rootView = LayoutInflater.from(context).inflate(R.layout.dialog_take_money_rule, null);
        setContentView(rootView);

        tv_content = rootView.findViewById(R.id.tv_content);
        tv_link = rootView.findViewById(R.id.tv_link);
        tv_link.setOnClickListener(this);
        new TimeCount(5000, 1000, new TimeCount.TickListener() {
            @Override
            public void onTick(long millisUntilFinished) {
                tv_link.setText("还剩" + millisUntilFinished / 1000 + "秒");
            }

            @Override
            public void onFinish() {
                tv_link.setEnabled(true);
                tv_link.setText("我同意");
            }
        }).start();
        tv_content.setText(rule);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_link:
                DataUtils.setFirstTakeMoney(mContext, true);
                dismiss();
                break;
        }
    }


}
